﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DelegatesAndEvents
{
    class DelegatesAndEventTest
    {
        public delegate void SequenceDelegate();

        public static void SumOfFirstSequence() 
        {
            decimal sum = 1;
            decimal toAdd = 0.5m;
            while (toAdd.CompareTo(0.0001m)>0)
            {
                sum += toAdd;
                toAdd /= 2; 
            }
            Console.WriteLine("{0:F2}",sum);
        }

        public static void SumOfSecondSequence()
        {
            decimal sum = 1;
            decimal toAdd = 0.5m;
            decimal factoriel = 2;
            int memberNumber= 2;
            while (toAdd.CompareTo(0.0001m) > 0)
            {
                sum += toAdd;
                memberNumber++;
                factoriel *= memberNumber;
                toAdd = 1 / factoriel;
            }
            Console.WriteLine("{0:F2}", sum);
        }

        public static void SumOfThirthSequence()
        {
            decimal sum = 1;
            decimal toAdd = 0.5m;
            while (Math.Abs(toAdd).CompareTo(0.00001m) > 0)
            {
                sum += toAdd;
                toAdd /= 2;
                toAdd *= -1;
            }
            Console.WriteLine("{0:F2}", sum);
        }

        static void Main(string[] args)
        {
            //SequenceDelegate myDelegate = SumOfFirstSequence;
            //myDelegate += SumOfSecondSequence;
            //myDelegate += SumOfThirthSequence;
            //myDelegate();
            PersonV2 person = new PersonV2("Pesho", "Peshov", "male", "vcehra");
            person.LastName = "asda";
        }
    }
}
